package com.mall.controller;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.mall.annotation.OperationLog;
import com.mall.db.domain.Goods;
import com.mall.db.service.GoodsService;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.servlet.ModelAndView;

import javax.annotation.Resource;
import java.util.List;
import java.util.Map;

@Controller
@RequestMapping("/system/gl")
public class ListController extends BaseController<Goods>{
    @Resource(name ="goodsService")
    private GoodsService gs;


    @Override
    public Map<String, Object> find(Goods goods) {
        PageHelper.startPage(goods.getPage(),goods.getLimit());
        QueryWrapper<Goods> qw = new QueryWrapper<>();
        List<Goods> list = gs.list(qw);
        PageInfo<Goods> page = new PageInfo<>(list,goods.getLimit());
        return this.findMap(page.getList(), page.getTotal());
    }

    @RequestMapping("/look")
    public ModelAndView look(ModelAndView mav,
                             @RequestParam(value = "id") int id){
        mav.addObject("lid",id);
        return mav;
    }

    @Override
    @OperationLog(value = "删除商品列表",type = 0)
    public Map<String, Object> delete(Goods goods) {
        boolean b=gs.removeById(goods);
        return this.iud("删除",b,goods);
    }

    @RequestMapping("/takeDown/{id}")
    @OperationLog(value = "下架商品",type = 0)
    public Map<String, Object> takeDown(Goods goods) {
        boolean b=gs.updateById(goods);
        return this.iud("下架商品",b,goods);
    }
    @RequestMapping("/updateNews/{id}")
    @OperationLog(value = "上架商品",type = 0)
    public Map<String, Object> updateNews(Goods goods) {
        boolean b=gs.updateById(goods);
        return this.iud("上架商品",b,goods);
    }

}
